<?php
	session_start();
	require_once('../php/funciones.php');
        require_once '../php/clases/Carrito.php';
        require_once '../php/clases/ItemCarrito.php';
        require_once '../php/clases/ItemSCarrito.php';
        require_once '../php/clases/Productos.php';
        require_once '../php/clases/Tools.php';
        require_once '../php/conf/config.php';
        $tienda = _SITE_URL_."/tienda";
		$estaPagina=$_SERVER['PHP_SELF'];
?>

<html>
<head>
		<meta charset="utf-8">
		<title>Resumen</title>
		<link rel="stylesheet" type="text/css" href="../css/estiloPrincipal.css"/>
		<link rel="stylesheet" type="text/css" href="../css/estilo_login.css" />
		<link rel="stylesheet" type="text/css" href="../css/fonts.css" />
                <link rel="stylesheet" type="text/css" href="css/shop.css" />
                <link rel="stylesheet" type="text/css" href="css/confirmarproductos.css" />
		<link href='http://fonts.googleapis.com/css?family=Source+Sans+Pro' rel='stylesheet' type='text/css'>
		<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
		<script type="text/javascript" src="../js/form.js"></script>
		<script type="text/javascript" src="../js/login.js"></script>
		<script type="text/javascript" src="../js/funciones.js"></script>
                <script type="text/javascript" src="js/cart-efect.js"></script>
		<script type="text/javascript" src="../js/sonido-hover.js"></script>
		<script type="text/javascript">
		function refresh() {
			
			if(comprobarErrores()){
				//alert(comprobarErrores());
				//alert("recarga");
				window.setTimeout('recarga()',200);
			}
		}
		function recarga() {
		    location.reload();
		}
		function comprobarErrores()
		{
			if (document.getElementById('error-login').innerHTML == "") {
				//alert("error");
				return false;
			}
			return true;
		}
		</script>
</head>
	<body>
	
	<div id="contenedor">
		<div id="head" >
                    <div id="formulario-login" class="drawer" style="right: -400px;">

					<form class="form-despleg drawer-form" id="login-form" action="<?php htmlspecialchars($estaPagina); ?>" method="POST" style="height: 600px;">
						
							<a id="cerrar-login" class="close-drawer" href="#">+</a>
						
						<h2>Login</h2>
									
						<div class="form-group">
						
							<input type="text" name="login" class="form-control info-usu" placeholder="Email" id="id-field-login">
						
						</div>
						
						<div class="form-group">
							<input type="password" value="" name="password" class="form-control info-usu" placeholder="Contrase&ntilde;a" id="id-field-password">
						</div>
						<div id="error-login" class="box-error"></div>
						<button name="btnEntrar" class="btn-submit" type="button" onclick="comprobarAutenticacion('../php/Login.php'); refresh();">Entrar</button>

					</form>
			</div>
		    
                               <div id="contenedorMenu">
				<ul id="menu" class="efectoMenu nav">
					<li>
						<a href="../principal.php">Principal</a>
						<audio style="display: none" id="beep-two0" controls preload="auto">
							<source src="../sonidos/click.mp3" controls></source>
							<source src="../sonidos/click.ogg" controls></source>
							Your browser isn't invited for super fun audio time.
						</audio>
					</li>
					<li>
						<a href="../historia.php">Introducci&oacute;n</a>
						<audio  style="display: none" id="beep-two1" controls preload="auto">
							<source src="../sonidos/click.mp3" controls></source>
							<source src="../sonidos/click.ogg" controls></source>
							Your browser isn't invited for super fun audio time.
						</audio>
					</li>
					<li>
						<a href="#">Proceso</a>
						<audio  style="display: none" id="beep-two2" controls preload="auto">
							<source src="../sonidos/click.mp3" controls></source>
							<source src="../sonidos/click.ogg" controls></source>
							Your browser isn't invited for super fun audio time.
						</audio>
					</li>
					<li>
						<a href="#">Productos</a>
						<audio  style="display: none" id="beep-two3" controls preload="auto">
							<source src="../sonidos/click.mp3" controls></source>
							<source src="../sonidos/click.ogg" controls></source>
							Your browser isn't invited for super fun audio time.
						</audio>
					</li>
					<li class="marca">
						<a href="<?php echo $tienda; ?>">Tienda</a>
						<audio  style="display: none" id="beep-two4" controls preload="auto">
							<source src="../sonidos/click.mp3" controls></source>
							<source src="../sonidos/click.ogg" controls></source>
							Your browser isn't invited for super fun audio time.
						</audio>
					</li>
					
				</ul>
				
			</div>

				<div id="contenedorSesion" >
					<?php
						if( isset($_SESSION['usuario']) ){
							$estaPagina=$_SERVER['PHP_SELF'];
                                                        echo "Usuario: " . $_SESSION['usuario'];
                                                      //  echo '<a id="enlacePerfil" style="margin-left:1%;" class="_drawer-btn no-pjax" href="#">Mi perfil</a>';
							echo '<a id="enlaceSesion" style="margin-left:1%;" class="_drawer-btn no-pjax" href="../session_end.php">Salir</a>';
                                                        
                                                }else{
							echo " Invitado";
						}
                                                
					?>
				</div>
			
		</div>
                
		<div id="contenido">
			
                            <?php
                                if (empty($_SESSION['usuario']))
                                {
                                    echo '<div id="titulo-shop">
                                                 <h3>Debes estar registrado para comprar</h3>
                                            </div>';
                                }else{
                                    echo '<div id="titulo-shop">
                                                 <h3>Resumen de tus productos</h3>
                                            </div>';
                                }
                            ?>
                           
                        <div id="catalogo">
                       
                                <div id="product-page">
                         
                                <table id="table-resume-product">
                                <thead>
                                    <tr>
                                        <th>Producto</th>
                                        <th>Descripcion</th>
                                        <th>Precio</th>
                                        <th>Cantidad</th>
                                    </tr>
                                </thead>
                                 <tbody>
                                  
                            <?php
                                foreach ($_SESSION['carrito'] as $nombre => $total)
                                {
                                     $nombre= explode("_", $nombre);
                                     $codigos = $nombre[1];
                                     $array_codigos = explode("-", $codigos);
                                     $cod_categoria = $array_codigos[0];
                                     $cod_subcat = $array_codigos[1];
                                    $p = new Producto($cod_categoria, $cod_subcat);
                                     echo '<tr class="cart_total_price">
                                        <td class="celdas-product"><img widtd="70" height="70" src="../images/Productos/01-01.jpg"/></td>
                                        <td class="celdas-product">'.$nombre[0].'</td>
                                        <td class="celdas-product">'.$p->aDefinition['precio'].' EUR</td>
                                        <td class="celdas-product">'.$total.'</td>
                                    </tr>';
                                    unset($p);
                                }
                                ?>
                                
                                </tbody>
                                        <tfoot>
                                            <tr class="cart_total_price">
                                                <td class="celdas-product" colspan="2" rowspan="2"></td>
                                                <td id="" class="celdas-product" >Total</td>
                                                <td id="" class="celdas-product"><?php $precioT = sprintf("%01.2f", $_SESSION['precioAcum']); echo $precioT . " EUR"; ?></td>
                                            </tr>
                                            <tr class="cart_total_price">
                                                <td></td>
                                                <td colspan="3" class="celdas-product"></td>
                                                <td id="" class="celdas-product" colspan="2"></td>
                                            </tr>
                                            
                                        </tfoot>
                                        </table>
                                <?php
                                    if (empty($_SESSION['usuario']))
                                    {
                                        echo '<a href="'._SITE_URL_.'/register.php" style="margin-top=500px" class="new-account" id="reg-compra">Registrarse</a>
					<a href="javascript:void(0)"  onclick="mostrarLogin();" style="" class="new-account" id="sesion-compra">Login</a>
					';
                                    }else{
                                        echo '<a id="boton-pago" class="new-account" href="aceptar_pago.php">Continuar ></a>';
                                    }
                                ?>
                                    </div>
                    </div>
		</div>
                
			<div id="footer">
				
				<!--  <div id="contenedorPie">
					<ul id="pie" class="efectoMenu">
						<li>Pie 1</li>
						<li>Pie 2</li>
						<li>Pie 3</li>
					</ul>
				</div>-->
				<div id="contenedorRedes">
					<ul id="redesSociales" class="efectoMenu">
						<li>Twitter</li>
						<li>Facebook</li>
						<li>Redimensionar</li>
					</ul>
				</div>
			</div>
	</div>
			
	</body>
</html>
